package com.yike.user.controller;

import com.yike.user.entity.AgentCount;
import com.yike.user.service.AgentCountService;
import lombok.extern.slf4j.Slf4j;
import com.yike.user.param.AgentCountPageParam;
import com.yike.common.base.BaseController;
import com.yike.common.api.ApiResult;
import com.yike.common.pagination.Paging;
import com.yike.common.log.Module;
import com.yike.common.log.OperationLog;
import com.yike.common.enums.OperationLogType;
import com.yike.common.api.Add;
import com.yike.common.api.Update;
import org.springframework.validation.annotation.Validated;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;

/**
 * 代理商分佣统计 控制器
 *
 * @author Sakura
 * @since 2024-11-13
 */
@Slf4j
@RestController
@RequestMapping("/agentCount")
@Module("user")
@Api(value = "代理商分佣统计API", tags = {"代理商分佣统计"})
@ApiIgnore
public class AgentCountController extends BaseController {

    @Autowired
    private AgentCountService agentCountService;

    /**
     * 添加代理商分佣统计
     */
    @PostMapping("/add")
    @OperationLog(name = "添加代理商分佣统计", type = OperationLogType.ADD)
    @ApiOperation(value = "添加代理商分佣统计", response = ApiResult.class)
    public ApiResult<Boolean> addAgentCount(@Validated(Add.class) @RequestBody AgentCount agentCount) throws Exception {
        boolean flag = agentCountService.saveAgentCount(agentCount);
        return ApiResult.result(flag);
    }

    /**
     * 修改代理商分佣统计
     */
    @PostMapping("/update")
    @OperationLog(name = "修改代理商分佣统计", type = OperationLogType.UPDATE)
    @ApiOperation(value = "修改代理商分佣统计", response = ApiResult.class)
    public ApiResult<Boolean> updateAgentCount(@Validated(Update.class) @RequestBody AgentCount agentCount) throws Exception {
        boolean flag = agentCountService.updateAgentCount(agentCount);
        return ApiResult.result(flag);
    }

    /**
     * 删除代理商分佣统计
     */
    @PostMapping("/delete/{id}")
    @OperationLog(name = "删除代理商分佣统计", type = OperationLogType.DELETE)
    @ApiOperation(value = "删除代理商分佣统计", response = ApiResult.class)
    public ApiResult<Boolean> deleteAgentCount(@PathVariable("id") Long id) throws Exception {
        boolean flag = agentCountService.deleteAgentCount(id);
        return ApiResult.result(flag);
    }

    /**
     * 获取代理商分佣统计详情
     */
    @GetMapping("/info/{id}")
    @OperationLog(name = "代理商分佣统计详情", type = OperationLogType.INFO)
    @ApiOperation(value = "代理商分佣统计详情", response = AgentCount.class)
    public ApiResult<AgentCount> getAgentCount(@PathVariable("id") Long id) throws Exception {
        AgentCount agentCount = agentCountService.getById(id);
        return ApiResult.ok(agentCount);
    }

    /**
     * 代理商分佣统计分页列表
     */
    @PostMapping("/getPageList")
    @OperationLog(name = "代理商分佣统计分页列表", type = OperationLogType.PAGE)
    @ApiOperation(value = "代理商分佣统计分页列表", response = AgentCount.class)
    public ApiResult<Paging<AgentCount>> getAgentCountPageList(@Validated @RequestBody AgentCountPageParam agentCountPageParam) throws Exception {
        Paging<AgentCount> paging = agentCountService.getAgentCountPageList(agentCountPageParam);
        return ApiResult.ok(paging);
    }

}

